<?php

/*

  Action	$2

  +1 Action
  Discard any number of cards.
  +1 Card per card discarded.

 */

class Cellar extends Card implements iAction, iKingdom, iBasic {

    private $numOfDiscardedCards;
    
    public function __construct() {
        parent::__construct("Cellar", 2);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Action",
            "Discard any number of cards. +1 Card per card discarded.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action", "gets +1 action");
        
        $cards = $game->getPlayHand();
        if (sizeof($cards) > 0) {

            $output = MySocket::GetUserReply($game, Input_ChooseMany, $cards, 0, -1, null, "Choose cards to discard");


            ScreenDisplay::addScreenMessage($game, true, "discard  " . nicePrint($output), "discards " . sizeof($output) . " cards");
            foreach ($output as $p) {
                $game->moveCardFromPileToPile($p, PlayHand, DiscardPile);
            }

            $this->numOfDiscardedCards = sizeof($output);
            $drawed_cards = $game->drawCards(sizeof($output));
            ScreenDisplay::addScreenMessage($game, false, " and draw  " . nicePrint($drawed_cards), " and draws " . sizeof($drawed_cards) . " cards");
        }
        else {
            $this->numOfDiscardedCards = 0;
        }

        $game->cardActionFinished();
        return true;
    }
    
    public function undoParamsPlay($undoParams) {
        if ($this->numOfDiscardedCards == 0)
            return array($this->undoPlay, $undoParams);
        return array(false, $undoParams);
    }

    public function undo(Game $game, $undoParams) {
        $game->addActions(-1);
    }

}

?>